package com.dididoctor.patient.Activity.Usercentre.Combo;

import android.content.Context;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Http.MyHttpResponseHandler;
import com.dididoctor.patient.MV.BasePresenter;
import com.dididoctor.patient.MV.BusinessClient;
import com.dididoctor.patient.MV.Response;
import com.dididoctor.patient.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/15.
 */
public class ComboPresenter extends BasePresenter {

    private ComboView view;

    public ComboPresenter(Context context, ComboView view) {
        super(context, view);
        this.view = view;
    }

    public void getcombo(int pageIndex) {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getId());
        params.put("pageIndex", Util.toString(pageIndex));
        params.put("pageSize", "10");
        params.put("token", Token.getToken());

        BusinessClient.post(ConstantValue.mypkg, params, new MyHttpResponseHandler() {
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
            private List<ComboBean> comboBeans = new ArrayList<ComboBean>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("orderList");
                    for (Map<String, String> map : maps) {
                        ComboBean comboBean = new ComboBean();
                        comboBean.setName(map.get("name"));
                        comboBean.setOrderId(Util.toString(map.get("orderId")));
                        comboBean.setDescription(map.get("description"));
                        comboBean.setStartTime(map.get("sta rtTime"));
                        comboBean.setWebUrl(map.get("webUrl"));
                        comboBean.setPicUrl(map.get("picUrl"));
                        comboBeans.add(comboBean);
                    }
                    view.getComboSucced(comboBeans);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getCombofail();
            }
        });

    }
}

